package com.testing;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.objects.MemberSearch;

import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;

public class Ireport {

	public static void main(String[] args) throws Exception{
		
		InputStream inputStream = new FileInputStream("D:/Throwdown/iReport/receiptv1.jrxml");
		
		MemberSearch memberSearchObject = new MemberSearch();
		ArrayList<MemberSearch> dataBeanList = new ArrayList<MemberSearch>();
		memberSearchObject.setName("Jackal");
		dataBeanList.add(memberSearchObject);
		memberSearchObject.setName("Annie");
		dataBeanList.add(memberSearchObject); 
		
		JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataBeanList);
		 
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("SEX", "twice");
		
		JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
		JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
		JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
		JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/Throwdown/iReport/test_jasper.pdf");
		
		System.out.println("End...");
	}

}
